package cn.flying.cloud.system.common.service;

import javax.annotation.Resource;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import cn.flying.cloud.system.dict.entity.SysDictData;
import cn.flying.cloud.system.dict.service.SysDictDataService;

/**
 * 查询枚举字典公共接口类
 *
 * @author: admin
 * @date: 2024年07月04日 00:27
 * @version: 1.0
 */
@Service
public class CodeService {

    @Resource
    private SysDictDataService sysDictDataService;

    /**
     * 根据枚举类型查询枚举字典
     *
     * @param type
     * @return
     */
    public Map<String, String> getCodeList(String type) {
        SysDictData dictData = new SysDictData();
        dictData.setDictType(type);
        List<SysDictData> list = sysDictDataService.getList(dictData);
        if (CollectionUtils.isEmpty(list)) {
            return new HashMap<>();
        }
        Map<String, String> map = list.stream().collect(Collectors.toMap(SysDictData::getCode, SysDictData::getText));
        return map;
    }
}
